package Jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

/**
 * 快捷方式的查询：
 * 1. selector:选择器
 *   使用document直接调用
 * - 使用的方法：Elements  select(String cssQuery)
 *   String  cssQuery:和Css选择器有点相像
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-18-11:32 11:32
 */
public class SelectorDemo {
    public static void main(String[] args) throws URISyntaxException, IOException {
        String path = JsoupDemo.class.getClassLoader().getResource("student.xml").toURI().getPath();
        Document document = Jsoup.parse(new File(path), "utf-8");
        //选择所有name标签
        Elements name = document.select("name");
        System.out.println(name);
        System.out.println("--------------");
        //选择user标签class属性为username
        Elements username = document.select("user[class='username']");
        System.out.println(username);
        System.out.println("-----------------");
        //选择user标签id属性为2的name子标签
        Elements user2_name = document.select("user[id='2']>name");
        System.out.println(user2_name);
    }
}
